package com.rss.inbound.dao.impl;

// default package
// Generated Jan 10, 2013 11:00:14 PM by Hibernate Tools 3.4.0.CR1

import static org.hibernate.criterion.Example.create;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.SessionFactory;

import com.rss.inbound.beans.CntnCatgry;
import com.rss.inbound.dao.CntnCatgryDAO;

/**
 * Home object for domain model class CntnCatgry.
 * 
 * @see .CntnCatgry
 * @author Hibernate Tools
 */
public class CntnCatgryDAOImpl implements CntnCatgryDAO
{

    private static final Log log	    = LogFactory
						    .getLog(CntnCatgryDAOImpl.class);

    private SessionFactory   sessionFactory = null;

    public void persist(CntnCatgry transientInstance)
    {
	log.debug("persisting CntnCatgry instance");
	try
	{
	    sessionFactory.getCurrentSession().persist(transientInstance);
	    log.debug("persist successful");
	}
	catch (RuntimeException re)
	{
	    log.error("persist failed", re);
	    throw re;
	}
    }

    public void attachDirty(CntnCatgry instance)
    {
	log.debug("attaching dirty CntnCatgry instance");
	try
	{
	    sessionFactory.getCurrentSession().saveOrUpdate(instance);
	    log.debug("attach successful");
	}
	catch (RuntimeException re)
	{
	    log.error("attach failed", re);
	    throw re;
	}
    }

    @SuppressWarnings("deprecation")
    public void attachClean(CntnCatgry instance)
    {
	log.debug("attaching clean CntnCatgry instance");
	try
	{
	    sessionFactory.getCurrentSession().lock(instance, LockMode.NONE);
	    log.debug("attach successful");
	}
	catch (RuntimeException re)
	{
	    log.error("attach failed", re);
	    throw re;
	}
    }

    public void delete(CntnCatgry persistentInstance)
    {
	log.debug("deleting CntnCatgry instance");
	try
	{
	    sessionFactory.getCurrentSession().delete(persistentInstance);
	    log.debug("delete successful");
	}
	catch (RuntimeException re)
	{
	    log.error("delete failed", re);
	    throw re;
	}
    }

    public CntnCatgry merge(CntnCatgry detachedInstance)
    {
	log.debug("merging CntnCatgry instance");
	try
	{
	    CntnCatgry result = (CntnCatgry) sessionFactory.getCurrentSession()
		    .merge(detachedInstance);
	    log.debug("merge successful");
	    return result;
	}
	catch (RuntimeException re)
	{
	    log.error("merge failed", re);
	    throw re;
	}
    }

    public CntnCatgry findById(int id)
    {
	log.debug("getting CntnCatgry instance with id: " + id);
	try
	{
	    CntnCatgry instance = (CntnCatgry) sessionFactory
		    .getCurrentSession().get("CntnCatgry", id);
	    if (instance == null)
	    {
		log.debug("get successful, no instance found");
	    }
	    else
	    {
		log.debug("get successful, instance found");
	    }
	    return instance;
	}
	catch (RuntimeException re)
	{
	    log.error("get failed", re);
	    throw re;
	}
    }

    @SuppressWarnings("unchecked")
    public List<CntnCatgry> findByExample(CntnCatgry instance)
    {
	log.debug("finding CntnCatgry instance by example");
	try
	{
	    List<CntnCatgry> results = (List<CntnCatgry>) sessionFactory
		    .getCurrentSession().createCriteria("CntnCatgry")
		    .add(create(instance)).list();
	    log.debug("find by example successful, result size: "
		    + results.size());
	    return results;
	}
	catch (RuntimeException re)
	{
	    log.error("find by example failed", re);
	    throw re;
	}
    }

    public SessionFactory getSessionFactory()
    {
	return sessionFactory;
    }

    public void setSessionFactory(SessionFactory sessionFactory)
    {
	this.sessionFactory = sessionFactory;
    }
}
